package com.viphuli.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import butterknife.Bind;

import com.offroader.core.OffRoaderActivity;
import com.offroader.utils.OnlineParamUtils;
import com.offroader.utils.PhoneUtils;
import com.umeng.message.PushAgent;
import com.viphuli.app.R;
import com.viphuli.common.MyApp;
import com.viphuli.common.MyPageHelper;
import com.viphuli.common.PerferencesHelper;

/**
 * 闪屏
 * 
 * @author li.li
 *
 */
public class WelcomeActivity extends OffRoaderActivity implements AnimationListener {

	@Bind(R.id.id_welcome)
	protected ViewGroup welcome;

	@Override
	public int getContentView() {
		return R.layout.act_welcome;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		//友盟在线参数
		OnlineParamUtils.update();

		//友盟推送
		PushAgent mPushAgent = PushAgent.getInstance(this);
		mPushAgent.enable();
		//		String device_token = UmengRegistrar.getRegistrationId(this);
		//		LogUtils.info("@@@device_token|" + device_token);

	}

	@Override
	public void initView() {

		Animation anim = AnimationUtils.loadAnimation(this, R.anim.splash_alpha_in);
		anim.setAnimationListener(this);

		welcome.startAnimation(anim);

	}

	@Override
	public void initData() {
	}

	@Override
	public void onAnimationEnd(Animation anim) {


		int guideVCode = PerferencesHelper.getInstance().readInt(GuideActivity.GUIDE_V_CODE_KEY);
		
		if(PhoneUtils.getAppVersionCode(MyApp.getInstance()) > guideVCode){//去引导页
			
			Intent intent = new Intent(this, GuideActivity.class);
			startActivity(intent);
			
		}else{//去首页
			
			MyPageHelper.main.showMyPage(this);
			
		}

		
	}

	@Override
	public void onAnimationRepeat(Animation anim) {

	}

	@Override
	public void onAnimationStart(Animation anim) {

	}

}
